import React from 'react';
import { Router } from 'dva/router';
import App from './routes/app';




export default function({ history, app }) {
  

  function requireAuth(nextState, replace, callback) {

    app._store.dispatch({
      type: 'app/enterAuth',
      payload: {},
      onComplete: callback
    });
  }
  const routes = [{
    path: '/',
    component: App,
    getIndexRoute(nextState, cb) {
      require.ensure([], require => {
        cb(null, { component: require('./routes/dashboard') })
      })
    },

    
    childRoutes: [{
      path: 'dashboard',
      name: 'dashboard',
      getComponent(nextState, cb) {
        require.ensure([], require => {
          cb(null, require('./routes/dashboard'))
        })
      }
    }, {
      path: 'login',
      name: 'login',
      getComponent(nextState, cb) {
        require.ensure([], require => {
          cb(null, require('./routes/login'))
        })
      }
    },{
      path: 'wilddog/wilddogUp',
      name: 'wilddogUp',
      getComponent(nextState, cb) {
        require.ensure([], require => {
          cb(null, require('./routes/wilddog/wilddogUp'))
        })
      }
    },{
      path: 'wilddog/wilddogRoom',
      name: 'wilddogRoom',
      getComponent(nextState, cb) {
        require.ensure([], require => {
          cb(null, require('./routes/wilddog/wilddogRoom'))
        })
      }
    },{
      path: 'wilddog/room/:roomId',
      name: 'wilddogMessage',
      getComponent(nextState, cb) {
        require.ensure([], require => {
          cb(null, require('./routes/wilddog/wilddogMessage'))
        })
      }
    },{
      path: 'answer/terms',
      name: 'terms',
      getComponent(nextState, cb) {
        require.ensure([], require => {
          cb(null, require('./routes/answer/terms'))
        })
      }
    }, {
      path: 'users',
      name: 'users',
      getComponent(nextState, cb) {
        require.ensure([], require => {
          cb(null, require('./routes/users'))
        })
      }
    }, {
      path: 'ui/ico',
      name: 'ui/ico',
      getComponent(nextState, cb) {
        require.ensure([], require => {
          cb(null, require('./routes/ui/ico'))
        })
      }
    }, {
      path: 'ui/search',
      name: 'ui/search',
      getComponent(nextState, cb) {
        require.ensure([], require => {
          cb(null, require('./routes/ui/search'))
        })
      }
    }, {
      path: '*',
      name: 'error',
      getComponent(nextState, cb) {
        require.ensure([], require => {
          cb(null, require('./routes/error'))
        })
      }
    }]
  }]

  return <Router history={history} routes={routes} />
}
